/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package j2ee.impl;

import j2ee.EjbRelationType;
import j2ee.EjbRelationshipRoleType;
import j2ee.J2eePackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Ejb Relation Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link j2ee.impl.EjbRelationTypeImpl#getEjbRelationshipRole <em>Ejb Relationship Role</em>}</li>
 *   <li>{@link j2ee.impl.EjbRelationTypeImpl#getEjbRelationName <em>Ejb Relation Name</em>}</li>
 *   <li>{@link j2ee.impl.EjbRelationTypeImpl#getId <em>Id</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EjbRelationTypeImpl extends EObjectImpl implements EjbRelationType {
	/**
	 * The cached value of the '{@link #getEjbRelationshipRole() <em>Ejb Relationship Role</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEjbRelationshipRole()
	 * @generated
	 * @ordered
	 */
	protected EList<EjbRelationshipRoleType> ejbRelationshipRole;

	/**
	 * The default value of the '{@link #getEjbRelationName() <em>Ejb Relation Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEjbRelationName()
	 * @generated
	 * @ordered
	 */
	protected static final String EJB_RELATION_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getEjbRelationName() <em>Ejb Relation Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEjbRelationName()
	 * @generated
	 * @ordered
	 */
	protected String ejbRelationName = EJB_RELATION_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final Object ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected Object id = ID_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EjbRelationTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return J2eePackage.Literals.EJB_RELATION_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EjbRelationshipRoleType> getEjbRelationshipRole() {
		if (ejbRelationshipRole == null) {
			ejbRelationshipRole = new EObjectContainmentEList<EjbRelationshipRoleType>(EjbRelationshipRoleType.class, this, J2eePackage.EJB_RELATION_TYPE__EJB_RELATIONSHIP_ROLE);
		}
		return ejbRelationshipRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getEjbRelationName() {
		return ejbRelationName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEjbRelationName(String newEjbRelationName) {
		String oldEjbRelationName = ejbRelationName;
		ejbRelationName = newEjbRelationName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, J2eePackage.EJB_RELATION_TYPE__EJB_RELATION_NAME, oldEjbRelationName, ejbRelationName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(Object newId) {
		Object oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, J2eePackage.EJB_RELATION_TYPE__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATIONSHIP_ROLE:
				return ((InternalEList<?>)getEjbRelationshipRole()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATIONSHIP_ROLE:
				return getEjbRelationshipRole();
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATION_NAME:
				return getEjbRelationName();
			case J2eePackage.EJB_RELATION_TYPE__ID:
				return getId();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATIONSHIP_ROLE:
				getEjbRelationshipRole().clear();
				getEjbRelationshipRole().addAll((Collection<? extends EjbRelationshipRoleType>)newValue);
				return;
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATION_NAME:
				setEjbRelationName((String)newValue);
				return;
			case J2eePackage.EJB_RELATION_TYPE__ID:
				setId(newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATIONSHIP_ROLE:
				getEjbRelationshipRole().clear();
				return;
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATION_NAME:
				setEjbRelationName(EJB_RELATION_NAME_EDEFAULT);
				return;
			case J2eePackage.EJB_RELATION_TYPE__ID:
				setId(ID_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATIONSHIP_ROLE:
				return ejbRelationshipRole != null && !ejbRelationshipRole.isEmpty();
			case J2eePackage.EJB_RELATION_TYPE__EJB_RELATION_NAME:
				return EJB_RELATION_NAME_EDEFAULT == null ? ejbRelationName != null : !EJB_RELATION_NAME_EDEFAULT.equals(ejbRelationName);
			case J2eePackage.EJB_RELATION_TYPE__ID:
				return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (ejbRelationName: ");
		result.append(ejbRelationName);
		result.append(", id: ");
		result.append(id);
		result.append(')');
		return result.toString();
	}

} //EjbRelationTypeImpl
